<?php

Loader::using("ext::libs::phpUI::impl::jquery::util::DependencyManager");

class CitiesDependency extends DependencyManager {

    public function getConstraintClass() {
        return "cities";
    }

    protected function getManagerClass() {
        return "CitiesManager";
    }

    public function renderCallback() {
        return "
            function(independentId, dependents){
                var val = $('#' + independentId).val();
                var deps = dependents;
                $.ajax({
                    url:'index.php?option=com_acaweb&controller=PublicData&task=GetMunicipioByNombreDepartamento&NombreDepartamento=' + val + '&ajax=true',
                    type: 'GET',
                    dataType:'json',
                    success: function (data){
                            var options = '<option> - Elegir - </option>';
                            for(var i in data){
                                if(typeof data[i] != 'function') {
                                    options += '<option value=\"' + data[i].Nombre + '\">';
                                    options += data[i].Nombre;
                                    options += '</options>';
                                }
                            }
                            for(var i in deps){
                                if(typeof deps[i] != 'function'){
                                    $('#' + deps[i].dependent).html(options);
                                }
                            }
                        }
                    });
                }";
    }

    public function getEvent() {
        return "change";
    }

}

?>